<?php
$action = trim($_POST["action"]);
$current = trim($_POST["current"]); 
$time = trim($_POST["time"]); 
  if ($action == "process"){

  }
  else if ($action == "skip"){

  }
  else if ($action == "abort"){

  } 
	///RRRRRRRRRRRRRRRRRRRRRRRRR
	file_put_contents('FOPLogTime.txt', $current.'|'.$time.'|'.$action."\n", FILE_APPEND | LOCK_EX);

	//Incrémente le current line et sauvegarde dans le fichier current.txt
        $current = $current+1;

///////////////////////////////////////////////supprimer
	///$fp = fopen ("current.txt", "r+");
	///fseek ($fp, 0);
	///fputs ($fp, $current);
	///fclose ($fp);
//////////////////////////////////////////////////
	
	
        $lines = file('script.txt');
	$tab=array();

///////////////////////////////////////////////Rajouter
	$taille = count($lines);
	if ($current >= $taille){
	  $current =0;
	  file_put_contents('FOPLogTime.txt', "");
	}
///////////////////////////////////////////////////

	foreach ($lines as $lineNumber => $lineContent)
	{
		$ligne['line']=$lineNumber;
		$ligne['instruction']=$lineContent;
		$tab[$lineNumber]=$ligne;
	}
        $json['change']="yes";
	$json['current_line']=$current;
	$json['type']="DATA";
//////////////////////R
	$json['nb_lignes']=$taille;
///////////////////////////////////////////////////////
	$json['content']=$tab;
///////////////////////////////////////////////Rajouter
	$chaine = $current."|".$taille;
	$fp = fopen ("current.txt", "w+");
	fseek ($fp, 0);
	fputs ($fp, $chaine );
	fclose ($fp);
///////////////////////////////////////////////////
        echo json_encode($json);
